<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button>测试</button>
    <button>测试</button>
    <button id="btn1">测试</button>
    <button class="btn">测试</button>
    <button>测试</button>
    <button b="3">测试</button>
    <button>测试</button>
    <script>
        // document.querySelector("button").onclick = () => {
        //     alert('测试')
        // }
        // document.querySelectorAll("button").forEach(item => {
        //     item.onclick = () => {
        //         alert('测试')
        //     }
        // })
        document.querySelector("#btn1").onclick = () => {
            alert('测试')
        }
        document.querySelector(".btn").onclick = () => {
            alert('测试123')
        }
        document.querySelector("button[b='3']").onclick = () => {
            alert("测试666")
        }
    </script>
</body>

</html>